home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ML_3DROT.ZIP / SOURCES / FIG9.PAS < prev    next >
Pascal/Delphi Source File  |  1996-12-26  |  3KB  |  135 lines

  1. {
  2.   Example of using the 3D "engine", by Maple Leaf, 1996
  3.  
  4.   This code is freeware. If you find it useful, feel free to do whatever
  5.   you want with it, with only one condiion: give some small greetings to
  6.   Maple Leaf in your productions that use parts of it.
  7.  
  8.                                                         Maple Leaf, '96
  9.  
  10.   btw, I'm too lazy to write down kilos of comments...   :-)
  11. }
  12. uses xmode,crt,engine3d;
  13.  
  14. var a,b:word;
  15.     pal:array[byte] of record r,g,b:byte end;
  16.     capag,cvpag : word;
  17.     dd:integer;
  18.     coord:array[0..730] of record x,y,z:integer end;
  19.     RealMapping : Boolean;
  20.     ch:char;
  21.     MaxPnt:word;
  22.     RotStep,TiltStep:longint;
  23.  
  24. Procedure GenFig;
  25. var angle:integer; hh:real; cnt:word;
  26. const rad:real = 40;
  27. begin
  28.   cnt:=0; angle:=0; hh:=0;
  29.   repeat
  30.     with coord[cnt] do begin
  31.       x:=Trunc(rad*cos(angle*pi/180));
  32.       y:=Trunc(rad*sin(angle*pi/180));
  33.       z:=Trunc(hh);
  34.     end;
  35.     hh:=hh+0.1;
  36.     inc(cnt);
  37.     inc(angle,7);
  38.     rad:=rad-0.056;
  39.   until cnt>699;
  40.   MaxPnt:=cnt;
  41. end;
  42.  
  43. Procedure PuneFig;
  44. var i:integer; cnt:word;
  45. begin
  46.   cnt:=0;
  47.   {xvwait;}
  48.   xclrvpage(capag);
  49.   for i:=0 to MaxPnt-1 do begin
  50.     _3dx:=coord[i].x+100;
  51.     _3dy:=coord[i].y;
  52.     _3dz:=coord[i].z+10;
  53.     asm
  54.        cmp RealMapping,1
  55.        je @1
  56.        call IntMapCoordinates
  57.        jmp @2
  58.     @1:call MapCoordinates
  59.     @2:
  60.     end;
  61.     xvplot(_2dx,_2dy,(i+2) shl 1,capag);
  62.   end;
  63. end;
  64.  
  65. Procedure IntroText;
  66. begin
  67.   Writeln('3D Figure, by Maple Leaf, 1996.');
  68.   Writeln(#13#10,' Hot keys are:'#13#10);
  69.   Writeln('   <M>     - Change mapping method (float/integer)');
  70.   Writeln('   <Left>  - Decrement horizontal speed of rotation');
  71.   Writeln('   <Right> - Increment horizontal speed of rotation');
  72.   Writeln('   <Up>    - Increment vertical speed of rotation');
  73.   Writeln('   <Down>  - Decrement vertical speed of rotation');
  74.   Writeln(#13#10'Press a key to start ...');
  75.   Readkey;
  76. end;
  77.  
  78. begin
  79.   ClrScr;
  80.   GenFig;
  81.   IntroText;
  82.   xinitvideo(0);
  83.   xclrvram;
  84.   for a:=1 to 255 do with pal[a] do begin
  85.     r:=Trunc(63);
  86.     g:=Trunc(63*a/255);
  87.     b:=Trunc(40{63*a/255});
  88.   end;
  89.   xsetpalette(@pal);
  90.   ZoomFactor:=500;
  91.   Perspective:=True;
  92.   SetObserverPosition(0,0,500);
  93.   SetAngles(0,0);
  94.   capag:=0;
  95.   cvpag:=3;
  96.   dd:=10;
  97.   RealMapping:=false;
  98.   RotStep:=2;
  99.   TiltStep:=3;
  100.   repeat
  101.    repeat
  102.  
  103.     xvwait;
  104.     xsetvpage(cvpag);
  105.  
  106.     RotAngle:=RotAngle+RotStep;
  107.     TiltAngle:=TiltAngle+TiltStep;
  108.     if RotAngle>359 then RotAngle:=360-RotAngle;
  109.     if RotAngle<0 then RotAngle:=360+RotAngle;
  110.     if TiltAngle>359 then TiltAngle:=360-TiltAngle;
  111.     if TiltAngle<0 then TiltAngle:=360+TiltAngle;
  112.     {SetAngles(RotAngle,TiltAngle);}
  113.  
  114.     PuneFig;
  115.  
  116.     inc(capag); if capag>3 then capag:=0;
  117.     inc(cvpag); if cvpag>3 then cvpag:=0;
  118.  
  119.    until keypressed;
  120.    ch:=readkey;
  121.    case UpCase(ch) of
  122.      'M': { Mapping mode } RealMapping:=not RealMapping;
  123.      #0: begin
  124.        ch:=readkey;
  125.        case ch of
  126.          #72: {Up}    inc(RotStep);
  127.          #80: {Down}  dec(RotStep);
  128.          #75: {Left}  dec(TiltStep);
  129.          #77: {Right} inc(TiltStep);
  130.        end;
  131.      end;
  132.    end;
  133.   until ch=#27;
  134.   textmode(25);
  135. end.